﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class ViewSubject : System.Web.UI.Page
    {
        private readonly BLRoutine _blroutine = new BLRoutine();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSubjectGrid();
            
            }

        }

        public void LoadSubjectGrid()
        {
            List<Subject> lsub= new List<Subject>();
            lsub = _blroutine.GetAllSubject();
            GridViewSubject.DataSource = lsub;
            GridViewSubject.DataBind();

        }
        protected void GridViewSubject_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton l = (LinkButton)e.Row.FindControl("DeleteButton");

                l.Attributes.Add("onclick", "javascript:return " +
                     "confirm('Are you sure you want to delete this record " +
                     DataBinder.Eval(e.Row.DataItem, "SubjectId") + "')");

            }
        }
        protected void GridViewSubject_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {

        }
        protected void GridViewSubject_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //int index = 1;
          //  int subjectId = (int)GridViewSubject.DataKeys[e.RowIndex].Value;
            //DeleteRecordByID(subjectId);
        }

      

        protected void GridViewSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = GridViewSubject.SelectedRow;
        }

        protected void GridViewSubject_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int subjectId = Convert.ToInt32(e.CommandArgument);
                _blroutine.DeleteSubjectbySubjectId(subjectId);
                LoadSubjectGrid();
            }
        }
    }
}